const yz = require('../comm/yz');
import axios from 'axios';

exports.classArray = function () {


    return [


        {

            name: "打样流程",
            sName: "打样",
            id: "proof"
        },
        {
            name: "大货流程",
            sName: "大货",
            id: "bulk"

        }
    ]

}

exports.getClass = function (classId) {
    // body...


    var cc = {};
    this.classArray().forEach(function (c) {

        if (c.id == classId) {
            cc = c

        }

    }, this);
    return cc
};

exports.getClassName = function (classId) {
    // body...

    var c = this.getClass(classId)
    return c.name
};




exports.getNodeStatus = function (statusId) {

    var nodeStatus = null
    this.nodeStatusArray().forEach(function (element) {


        if (element.id == statusId) {

            nodeStatus = element
        }
    }, this);

    return nodeStatus
};



exports.nodeStatusArray = function () {
    return [


        {

            name: "未执行",
            id: 0
        },
        {
            name: "执行中",
            id: 100

        },
        {
            name: "已完成",
            id: 200

        }
    ]
}


exports.fmtNode = function (node) {
    // body...
    if (!node) {
        node = {};
    }
    node.name = yz.IsNullThen(node.name, "未命名节点")
    node.rely = yz.IsNullThen(node.rely, []);
    node.id = yz.IsNullThen(node.id, "");
    node.members = yz.IsNullThen(node.members, []);
    node.managers = yz.IsNullThen(node.managers, []);
    node.statusId = yz.IsNullThen(node.statusId, 0);


};

exports.getJd = function (node) {
    // body...
    if (node.statusId >= 200) {
        node.jd = 100
    }


    node.jd = yz.IsNullThen(node.jd, 0);
    return node.jd;



};

exports.getStatusStr = function (node) {
    // body...
    if (yz.isNumber(node)) {

        if (node == 100) {

            return "success"
        }
        else {
            return ""
        }


    }


    if (this.getJd(node) == 100) {

        return "success"
    }
    else {
        return ""
    }

};

//获取整个流程的进度
exports.getFlowJd = function (flow) {



    var nodeList = flow.nodeList

    var a = 0;
    var b = 0;
    var taskIdArray = [];




    nodeList.forEach(function (node) {
        b = b + 100


        a = a + this.getJd(node)

    }, this);
    return yz.Percentage(a, b)
    // body...


};



